<?
    final class Principio_Model_SearchMapper
    {
        public static function search($string, $where = false)
        {
            if ($where)
            {
                switch ($where)
                {
                    case "type":
                        $res1 = Principio_Model_TypeMapper::search($string);
                        $res2 = Principio_Model_TypeExtTemplateMapper::search($string);
                        if ($res1 && $res2)
                        {
                            foreach ($res1 as $key => $res)
                                $search_result[$key] = $res;
                            foreach ($res2 as $key => $res)
                            {
                                if (isset($search_result[$key]))
                                {
                                    $search_res1 = $search_result[$key]->getResult();
                                    $search_res2 = $res->getResult();
                                    $search_res = $search_res1+$search_res2;
                                    $search_result[$key]->setResult($search_res);
                                }
                                else
                                    $search_result[$key] = $res;
                            }
                        }
                        elseif ($res1 || $res2)
                            $search_result = ($res1)? $res1 : $res2;
                        else
                            $search_result = false;
                    break;

                    case "companies":
                        $search_result = Principio_Model_CompanyMapper::search($string);
                    break;

                    case "account":
                        $search_result = Principio_Model_AccountMapper::search($string);
                    break;

                    case "spa":
                        $res1 = Principio_Model_SpaMapper::search($string);
                        $res2 = Principio_Model_SpaExtTemplatesMapper::search($string);
                        if ($res1 && $res2)
                        {
                            foreach ($res1 as $key => $res)
                                $search_result[$key] = $res;
                            foreach ($res2 as $key => $res)
                            {
                                if (isset($search_result[$key]))
                                {
                                    $search_res1 = $search_result[$key]->getResult();
                                    $search_res2 = $res->getResult();
                                    $search_res = $search_res1+$search_res2;
                                    $search_result[$key]->setResult($search_res);
                                }
                                else
                                    $search_result[$key] = $res;
                            }
                        }
                        elseif ($res1 || $res2)
                            $search_result = ($res1)? $res1 : $res2;
                        else
                            $search_result = false;
                    break;
                }
            }

            return $search_result;
        }
    }
?>